﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace Basic4Net.Controls
{
	/// <summary>
	/// 功能：扩展ImageButton控件
	/// <see cref="System.Web.UI.WebControls.ImageButton"/>
	/// </summary>
	[ToolboxData("<{0}:BNImageButton runat=\"server\"></{0}:BNImageButton>")]
	public class BNImageButton : ImageButton
	{
		/// <summary>
		/// 用户类型
		/// </summary>
		public enum EImageButtonType
		{
			View,
			Edit,
			Delete,
		}

		#region property

		private string _ConfirmMsg;
		/// <summary>
		/// 当点击按钮后出现的提示确认信息，默认为空（不提示信息）
		/// </summary>
		[Category("CustProperty"),
		Description("当点击按钮后出现的提示确认信息，默认为空（不提示信息）"),
		DefaultValue("")]
		public string ConfirmMsg
		{
			get
			{
				return _ConfirmMsg;
			}
			set
			{
				_ConfirmMsg = value;
			}
		}

		private bool _CheckSaved = true;
		/// <summary>
		/// 当点击按钮后是否检查当前页面是否已保存，默认为true（检查）
		/// </summary>
		[Category("CustProperty"),
		Description("当点击按钮后是否检查当前页面是否已保存，默认为true（检查）"),
		DefaultValue(true)]
		public bool CheckSaved
		{
			get
			{
				return _CheckSaved;
			}
			set
			{
				_CheckSaved = value;
			}
		}

		private string _CheckSavedMsg = string.Empty;
		/// <summary>
		/// CheckSaved为true显示的confirm提示信息，如果不设置或为空，则显示Page的提示信息
		/// </summary>
		[Category("CustProperty"),
		Description("CheckSaved为true显示的confirm提示信息，如果不设置或为空，则显示Page的提示信息"),
		DefaultValue("")]
		public string CheckSavedMsg
		{
			get
			{
				return _CheckSavedMsg;
			}
			set
			{
				_CheckSavedMsg = value;
			}
		}

		/// <summary>
		/// imagebutton 类型:view,edit,delete
		/// </summary>
		[Category("CustProperty"), Description("imagebutton类型")]
		public EImageButtonType ButtonType
		{
			set
			{
				this.SetButton(value);
			}
		}

		#endregion

		#region Private Method

		private void SetButton(EImageButtonType ButtonType)
		{
			if (ButtonType == EImageButtonType.View)
			{
				this.ToolTip = EImageButtonType.View.ToString();
				this.ImageUrl = "~/App_Themes/Default/images/icon/View.gif";
			}
			else if (ButtonType == EImageButtonType.Edit)
			{
				this.ToolTip = EImageButtonType.Edit.ToString();
				this.ImageUrl = "~/App_Themes/Default/images/icon/edit.gif";
			}
			else if (ButtonType == EImageButtonType.Delete)
			{
				this.ToolTip = EImageButtonType.Delete.ToString();
				this.ImageUrl = "~/App_Themes/Default/images/icon/delete.gif";
			}
		}
		#endregion
	}
}
